/**
 * Copyright (c), 2012~2020 iot.10086.cn All Rights Reserved
 *
 * @file tm_user.c
 * @date 2020/05/14
 * @brief
 */

/*****************************************************************************/
/* Includes                                                                  */
/*****************************************************************************/
#include "tm_data.h"
#include "tm_api.h"
#include "tm_user.h"

/*****************************************************************************/
/* Local Definitions ( Constant and Macro )                                  */
/*****************************************************************************/

/*****************************************************************************/
/* Structures, Enum and Typedefs                                             */
/*****************************************************************************/
/*************************** Property Func List ******************************/
struct tm_prop_tbl_t tm_prop_list[] = {
    TM_PROPERTY_RO($OneNET_LBS),
    TM_PROPERTY_RO($OneNET_LBS_WIFI),
    TM_PROPERTY_RW(OneNET_LED)
};
uint16_t tm_prop_list_size = ARRAY_SIZE(tm_prop_list);
/****************************** Auto Generated *******************************/

/***************************** Service Func List *******************************/
struct tm_svc_tbl_t tm_svc_list[] = {0};
uint16_t tm_svc_list_size = 0;
/****************************** Auto Generated *******************************/

/*****************************************************************************/
/* Local Function Prototype                                                  */
/*****************************************************************************/

/*****************************************************************************/
/* Local Variables                                                           */
/*****************************************************************************/

/*****************************************************************************/
/* Global Variables                                                          */
/*****************************************************************************/

/*****************************************************************************/
/* Function Implementation                                                   */
/*****************************************************************************/
/**************************** Property Func Read *****************************/
int32_t tm_prop_$OneNET_LBS_rd_cb(void *data)
{
    void *structure = NULL;
    struct prop_$OneNET_LBS_t val = {0};

    /** 根据实际情况修改需要返回的数组元素个数*/
    int32_t element_cnt =3;
    void *array = tm_data_array_create(element_cnt);
    int32_t i = 0;

    for(i = 0; i < element_cnt; i++)
	{
        /** 根据业务逻辑获取功能点值，设置到val */

		structure = tm_data_struct_create();
    	tm_data_struct_set_int32(structure, "mnc", val.mnc);
    	tm_data_struct_set_int32(structure, "mcc", val.mcc);
    	tm_data_struct_set_int32(structure, "lac", val.lac);
    	tm_data_struct_set_int32(structure, "cid", val.cid);
    	tm_data_struct_set_int32(structure, "networkType", val.networkType);
    	tm_data_struct_set_int32(structure, "ss", val.ss);
    	tm_data_struct_set_int32(structure, "signalLength", val.signalLength);
    	tm_data_struct_set_int32(structure, "ta", val.ta);
    	tm_data_struct_set_int32(structure, "flag", val.flag);
		tm_data_array_set_struct(array, structure);
	}
	tm_data_struct_set_data(data, "$OneNET_LBS", array);
	return 0;
}

int32_t tm_prop_$OneNET_LBS_WIFI_rd_cb(void *data)
{
    void *structure = tm_data_struct_create();
    struct prop_$OneNET_LBS_WIFI_t val = {0};
    /** 根据业务逻辑获取功能点值，设置到val */

    tm_data_struct_set_string(structure, "imsi", val.imsi);
    tm_data_struct_set_string(structure, "serverip", val.serverip);
    tm_data_struct_set_string(structure, "macs", val.macs);
    tm_data_struct_set_string(structure, "mmac", val.mmac);
    tm_data_struct_set_string(structure, "smac", val.smac);
    tm_data_struct_set_string(structure, "idfa", val.idfa);
    tm_data_struct_set_data(data, "$OneNET_LBS_WIFI", structure);
   return 0;
}

int32_t tm_prop_OneNET_LED_rd_cb(void *data)
{
	int32_t val = 0;

	/** 根据业务逻辑获取功能点值，设置到val */


	tm_data_struct_set_int32(data, "OneNET_LED", val);

	return 0;
}


/****************************** Auto Generated *******************************/

/**************************** Property Func Write ****************************/
int32_t tm_prop_OneNET_LED_wr_cb(void *data)
{
    int32_t val = 0;
    tm_data_get_int32(data, &val);
    /** 根据变量val的值，填入下发控制逻辑 */

    /***/
    return 0;
}


/****************************** Auto Generated *******************************/

/**************************** Property Func Notify ***************************/
int32_t tm_prop_$OneNET_LBS_notify(void *data, struct prop_$OneNET_LBS_t *val, uint32_t cnt, uint64_t timestamp, uint32_t timeout_ms)
{
    void *resource = NULL;
    void *array = NULL;
    int32_t ret = 0;
	int32_t i = 0;

    if(NULL == data)
    {
        resource = tm_data_create();
    }
    else
    {
        resource = data;
    }
	array = tm_data_array_create(cnt);

	for(i = 0; i < cnt; i++)
	{
		void *structure = tm_data_struct_create();
		tm_data_struct_set_int32(structure, "mnc", val[i].mnc);
		tm_data_struct_set_int32(structure, "mcc", val[i].mcc);
		tm_data_struct_set_int32(structure, "lac", val[i].lac);
		tm_data_struct_set_int32(structure, "cid", val[i].cid);
		tm_data_struct_set_int32(structure, "networkType", val[i].networkType);
		tm_data_struct_set_int32(structure, "ss", val[i].ss);
		tm_data_struct_set_int32(structure, "signalLength", val[i].signalLength);
		tm_data_struct_set_int32(structure, "ta", val[i].ta);
		tm_data_struct_set_int32(structure, "flag", val[i].flag);
		tm_data_array_set_struct(array, structure);
	}
		tm_data_set_data(resource, "$OneNET_LBS", array, timestamp);

		if(NULL == data)
		{
			ret = tm_post_property(resource, timeout_ms);
		}
		return ret;
}
int32_t tm_prop_$OneNET_LBS_WIFI_notify(void *data, struct prop_$OneNET_LBS_WIFI_t val, uint64_t timestamp, uint32_t timeout_ms)
{
    void *resource = NULL;
    void *structure = tm_data_struct_create();
	int32_t ret = 0;

    if(NULL == data)
    {
        resource = tm_data_create();
    }
    else
    {
        resource = data;
    }

	tm_data_struct_set_string(structure, "imsi", val.imsi);

	tm_data_struct_set_string(structure, "serverip", val.serverip);

	tm_data_struct_set_string(structure, "macs", val.macs);

	tm_data_struct_set_string(structure, "mmac", val.mmac);

	tm_data_struct_set_string(structure, "smac", val.smac);

	tm_data_struct_set_string(structure, "idfa", val.idfa);

    tm_data_set_struct(resource, "$OneNET_LBS_WIFI", structure, timestamp);

    if(NULL == data)
    {
        ret = tm_post_property(resource, timeout_ms);
    }

    return ret;
}

int32_t tm_prop_OneNET_LED_notify(void *data, int32_t val, uint64_t timestamp, uint32_t timeout_ms)
{
	void *resource = NULL;
    int32_t ret = 0;

    if(NULL == data)
    {
        resource = tm_data_create();
    }
    else
    {
        resource = data;
    }

    tm_data_set_int32(resource, "OneNET_LED", val, timestamp);

    if(NULL == data)
    {
        ret = tm_post_property(resource, timeout_ms);
    }

    return ret;
}


/****************************** Auto Generated *******************************/

/***************************** Event Func Notify *****************************/

/****************************** Auto Generated *******************************/

/**************************** Service Func Invoke ****************************/

/****************************** Auto Generated *******************************/
